package com.example.lxj.LegalCase.controller;

import java.util.List;
import java.util.Optional;

import com.example.lxj.base.annoation.Permission;
import com.example.lxj.base.controller.BaseController;
import com.example.lxj.base.entity.AjaxRes;
import com.example.lxj.base.entity.PageDTO;
import com.example.lxj.base.entity.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.example.lxj.LegalCase.entity.TbConsulation;
import com.example.lxj.LegalCase.service.ITbConsulationService;

import static com.github.pagehelper.page.PageMethod.startPage;

/**
 * 委托咨询Controller
 *
 * @author lxj
 * @date 2024-10-23
 */
@RestController
@RequestMapping("/LegalCase/consulation")
public class TbConsulationController extends BaseController {
    @Autowired
    private ITbConsulationService tbConsulationService;

    /**
     * 查询委托咨询列表
     */
    @Permission(value = "LegalCase:consulation:list")
    @GetMapping("/list")
    public TableDataInfo list(TbConsulation tbConsulation, PageDTO pageDTO) {
        startPage(Optional.ofNullable(pageDTO.getPageNo()).orElse(1),Optional.ofNullable(pageDTO.getPageSize()).orElse(10));
        List<TbConsulation> list = tbConsulationService.selectTbConsulationList(tbConsulation);
        return getDataTable(list);
    }

    /**
     * 获取委托咨询详细信息
     */
    @Permission(value = "LegalCase:consulation:query")
    @GetMapping(value = "/{id}")
    public AjaxRes getInfo(@PathVariable("id") Long id) {
        return success(tbConsulationService.selectTbConsulationById(id));
    }

    /**
     * 新增委托咨询
     */
    @Permission(value = "LegalCase:consulation:add")
    @PostMapping
    public AjaxRes add(@RequestBody TbConsulation tbConsulation) {
        return toAjax(tbConsulationService.insertTbConsulation(tbConsulation));
    }

    /**
     * 修改委托咨询
     */
    @Permission(value = "LegalCase:consulation:edit")
    @PutMapping
    public AjaxRes edit(@RequestBody TbConsulation tbConsulation) {
        return toAjax(tbConsulationService.updateTbConsulation(tbConsulation));
    }

    /**
     * 删除委托咨询
     */
    @Permission(value = "LegalCase:consulation:remove")
    @DeleteMapping("/{ids}")
    public AjaxRes remove(@PathVariable("ids") Long[] ids) {
        return toAjax(tbConsulationService.deleteTbConsulationByIds(ids));
    }
}
